package Udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpClient {
    public static void main(String[] args) throws Exception{
        //1.建立一个socket
        DatagramSocket socket = new DatagramSocket();

        //2.建个包
        String msg = "Hello JAVA";
        int port = 999;
        InetAddress inetAddress = InetAddress.getByName("127.0.0.1");//包的信息

        DatagramPacket packet = new DatagramPacket(msg.getBytes(),0,msg.length(),inetAddress,port);

        //3.发送包
        socket.send(packet);

        //4.关闭资源
        socket.close();
    }
}
